package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}15:02
 */
public class E10 {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        int[] result = new E10().exchange(nums);
        for (int i : result){
            System.out.println(i);
        }
    }
    public int[] exchange(int[] nums) {
//        int uneven = 0;
//        int even = 0;
//        int[] result1 = new int[nums.length];
//        int[] result2 = new int[nums.length];
//        for (int i = 0; i < nums.length;i++){
//            if (nums[i]%2==0){//为偶数
//                result1[even] = nums[i];
//                even++;
//            }else {
//                result2[uneven] = nums[i];
//                uneven++;
//            }
//        }
//        for (int i = 0; i < even;i++){
//            result2[uneven++] = result1[i];
//        }
//        return result2;
        int left = 0;
        int right = nums.length-1;
        while (left < right){
            if (nums[left]%2!=0){
                left++;
                continue;
            }
            if (nums[right]%2==0){
                right--;
                continue;
            }
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
        }
        return nums;
    }
}
